fix: pass branch/tag to git clone so --single-branch fetches correct ref#575
Open
yoonsoo-park wants to merge 1 commit into
Open
fix: pass branch/tag to git clone so --single-branch fetches correct ref#575yoonsoo-park wants to merge 1 commit into
yoonsoo-park wants to merge 1 commit into
Conversation
Without `-b <branch>`, `--single-branch` only fetches the default branch. The subsequent `fetch --depth=1 origin <sha>` silently fails to retrieve commits from other branches, causing the checkout to use the default branch content instead. Adds `-b` flag to all three clone paths (partial, authenticated, and standard GitPython). Adds two unit tests verifying the branch is forwarded. Fixes coderamp-labs#574
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--single-branchwithout-b <branch>only fetches the default branchfetch --depth=1 origin <sha>silently fails to retrieve commits from other branchesThis adds
-b <branch>(or-b <tag>) to all three clone code paths:git.Git().clone()with--filter=blob:none --sparse)git.Git().clone()with auth URL)git.Repo.clone_from()viabranchkwarg)Reproduction
gitingest -b my-feature-branch -t "$GITHUB_TOKEN" -o output.txt https://github.com/org/repoThe output contains the default branch's files, not
my-feature-branch's files. Verified with 4 different branches on a private repo — all produced byte-identical output matching the default branch.Root Cause
In
src/gitingest/clone.py,resolve_commit()correctly resolves the branch's HEAD SHA viagit ls-remote. However, the clone uses--single-branchwithout specifying which branch, so only the default branch is fetched. The subsequentfetch --depth=1 origin <sha>cannot retrieve commits from unfetched branches in a shallow single-branch clone.Changes
src/gitingest/clone.py: Add-bflag withconfig.branchorconfig.tagto all clone pathstests/test_clone.py: Add two tests verifying branch is forwarded to clone commandsFixes #574